home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4983 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c,comp.lang.c++,gnu.gcc.help,gnu.g++.help,comp.os.msdos.djgpp
  4. Subject: Re: float != float and floats as return types
  5. Date: 01 Feb 1996 23:40:22 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb1164022@qcd.lanl.gov>
  8. References: <4ej9lb$mpc@fu-berlin.de> <4elnjj$er4@server2.rz.uni-leipzig.de>
  9.     <4eqc7l$ugh@godzilla.zeta.org.au> <4eqtu3$ddo@der.twinsun.com>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: eggert@twinsun.com's message of 1 Feb 1996 09:40:19 -0800
  14.  
  15. In article <4eqtu3$ddo@der.twinsun.com> eggert@twinsun.com (Paul
  16. Eggert) writes: 
  17. <snip>
  18.    bde@zeta.org.au (Bruce Evans) writes:
  19.  
  20.    >    a = 1.0;
  21.    >    b = FLT_EPSILON / 4.0;
  22.    >    c = a + b;
  23.    >    assert(c == (float) (a + b));
  24.  
  25.    As far as I can tell the C Standard allows the assertion to either
  26.    succeed or fail, depending on the implementation.  The key phrase in
  27.    the standard is ``The values of floating operands and of the results of
  28.    floating expressions may be represented in greater precision and range
  29.    than that required by the type''.  So `c' might be represented in more
  30.    bits than `(float) (a + b)' (or vice versa! though this is more
  31.    controversial since it contradicts the Rationale, and it may be
  32.    corrected by the committee soon), and the assertion might fail.
  33.  
  34. I do not agree with this interpretation, as the footnote (technically,
  35. not part of the standard) clarifies: an assignment and cast both must
  36. truncate the result to the required precision. It can be subsequently
  37. widened to more precision: but that is a different matter.
  38.  
  39. Now whether `a+b' must always give the same answer (for constant a and
  40. b) may be debatable: but certainly not outside comp.std.c (or c++) :-)
  41.  
  42. Cheers
  43. Tanmoy
  44. --
  45. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  46. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  47. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  48. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  49. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  50. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  51.